#include "homewidget.h"
#include "globalconfig.h"

HomeWidget::HomeWidget(QWidget *parent)
    : AWidget{parent}
{
    channel = new ChannelNameWidget(this);
    mixer = new MixerWidget(this);
    peakGroup = new PeakGroup(this);

    const auto &cfgDev = GlobalConfig::getInstance().cfgDev();

    auto layout = new QGridLayout(this);
    layout->setSpacing(10 * ratio());

    auto vline = new AVLine(this);
    auto hline = new AHLine(this);
    vline->setStyleSheet(QString(R"(
        AVLine {
            border-right: none;
            background: transparent;
        }
    )"));

    layout->addWidget(channel, 0, 0, 1, cfgDev.mus.tru_ch);
    layout->addWidget(vline, 0, cfgDev.mus.tru_ch, 3, 1);
    layout->addWidget(mixer, 0, cfgDev.mus.tru_ch + 1, 1, cfgDev.out.tru_ch);
    layout->addWidget(hline, 1, 0, 1, cfgDev.mus.tru_ch + cfgDev.out.tru_ch + 1);
    auto peaks = peakGroup->peaks();
    for (int i = 0; i < peaks.size(); ++i) {
        if (i < cfgDev.mus.tru_ch) {
            layout->addWidget(peaks.at(i), 2, i);
        }
        else {
            layout->addWidget(peaks.at(i), 2, i + 1);
        }
    }

}

void HomeWidget::refresh()
{
    mixer->refresh();
    peakGroup->refresh();
}



